package com.csy.property.controller.community;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.commons.dto.SysUser;
import com.csy.feign.user.api.UserServiceApi;
import com.csy.property.community.domain.AjComplaintSuggest;
import com.csy.property.community.service.AjCompaintSuggestService;

import cn.hutool.core.util.IdUtil;


@RestController
@RequestMapping("/system/suggest")
public class AjComplaintSuggestController extends BaseController {

    @Resource
    private AjCompaintSuggestService ajCompaintSuggestService;

    @Resource
    private UserServiceApi userServiceApi;

    /**
     * 查询投诉建议列表
     * @param ajComplaintSuggest
     * @return
     */
    @GetMapping("/list")
    private PageResult list(AjComplaintSuggest ajComplaintSuggest){
        startPage();
        List<AjComplaintSuggest> ajComplaintSuggests = ajCompaintSuggestService.selectComplaintSuggestList(ajComplaintSuggest);
        return getData(ajComplaintSuggests);
    }

    /**
     * 统计投诉建议信息
     * @return
     */
    @GetMapping("/countSuggest")
    public BaseResponse<Integer> countSuggest(){
        int suggest = ajCompaintSuggestService.countSuggest();
        return BaseResponse.success(suggest);

    }

    /**
     * 获取投诉建议信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public BaseResponse<AjComplaintSuggest> getById(@PathVariable("id") String id){
        return BaseResponse.success(ajCompaintSuggestService.getById(id));
    }

    /**
     * 新增投诉建议信息
     * @param ajComplaintSuggest
     * @return
     */
    @PostMapping
    public BaseResponse<Integer> add(@RequestBody AjComplaintSuggest ajComplaintSuggest){
        ajComplaintSuggest.setComplaintSuggestId(IdUtil.getSnowflakeNextId());
        SysUser user = userServiceApi.getByUsername(ajComplaintSuggest.getUsername());
        ajComplaintSuggest.setUserId(user.getUserId());
        boolean b = ajCompaintSuggestService.save(ajComplaintSuggest);
        return toAjax(b == true ? 1 : 0);
    }

    /**
     * 更新
     * @param ajComplaintSuggest
     * @return
     */
    @PutMapping
    public BaseResponse<Integer> update(@RequestBody AjComplaintSuggest ajComplaintSuggest){

        boolean b = ajCompaintSuggestService.updateById(ajComplaintSuggest);
        return toAjax(b == true ? 1 : 0);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Integer> del(@PathVariable("id")String id){
        boolean b = ajCompaintSuggestService.removeById(id);
        return toAjax(b == true ? 1 : 0);
    }





}
